File bloomSrc = new File("/mnt/sdcard/sakura/bloom.i");
File cherishSrc = new File("/mnt/sdcard/sakura/cherish.i");

int cherishSelect;

String flowerNames[]=new String[15];

void loadFlowerNames() {
  //this array persists (not destroyable);
  flowerNames[0]="Acanthus";
  flowerNames[1]="Belladona";
  flowerNames[2]="Columbine";
  flowerNames[3]="Dandelion";
  flowerNames[4]="Elder";
  flowerNames[5]="Foxglove";
  flowerNames[6]="Ginger";
  flowerNames[7]="Hibiscus";
  flowerNames[8]="Iris";
  flowerNames[9]="Jasmine";
  flowerNames[10]="Knautia";
  flowerNames[11]="Lily";
  flowerNames[12]="Marigold";
  flowerNames[13]="Nightshade";
  flowerNames[14]="Orchid";
}

void testInput() {  //use this for quick keyboard testing
  println("test input");
  //  loadBloom();
  //  String IP=ipFetch();
  //  println(IP);
  //  makeBloom();
  //  OscMessage echoControl;
  //  int cherishSelect=0;
  //  echoControl = new OscMessage("/PLAN/name"+str(cherishSelect+1));
  //  echoControl.add(flowerNames[cherishSelect]);
  //  println(flowerNames[cherishSelect]);
  //
  //  oscP5x.send(echoControl, Conductor);
  f_align.setupFO();
}

String bloom[]=new String[4];
//String bloomData[]=new String[4];
/* format
 8 [flower index]
 I [flower name]
 108 [IP]
 */

/* FIXED ID, and user initiated rotations for each phsysical flower, */
String cherish[]=new String[5];  
/* 
 '0:0.0:0.0:0.0' [fixed index address:name:saved rotation value (gravity):(sakuraShape):(arbitrary)]
 */

void saveBloom() {
  saveStrings(bloomSrc.getAbsolutePath(), bloom);
}
void saveCherish() {
  saveStrings(cherishSrc.getAbsolutePath(), cherish);
}
void makeBloom() {
  ipFetch();
  println(IP);
  println(MAC);
  println("making bloom.i file");
  bloom[0]="X";
  bloom[1]="X";
  bloom[2]=IP;
  bloom[3]=MAC;
  saveBloom();
}
void loadCherish() {
  if (cherishSrc.exists()) {
    cherish = loadStrings(cherishSrc);
    println("cherish.i loaded");
  } else {
    println("uhoh, need a cherish.i file");
  }
  cherishPlan();
}
void cherishPlan() {
}
void planHandler(OscMessage theOscMessage, String addr) {
  if (addr.indexOf("toggle")>-1) {
    cherishSelect(theOscMessage, addr);
  }
  if (addr.indexOf("query")>-1) {
    cherishQuery();
  }
  if (addr.indexOf("start")>-1) {
    alignStart();
  }
  if (addr.indexOf("spin")>-1) {
    if (addr.indexOf("Fine")>-1) {
      sendSpin(theOscMessage, 3);
    } 
    if (addr.indexOf("Direct")>-1) {        
      sendSpin(theOscMessage, 4);
    }
    if (addr.indexOf("Up")>-1)
    {
      sendSpin(theOscMessage, 72);
    }
    if (addr.indexOf("Dn")>-1)
      sendSpin(theOscMessage, -72);
  }
  if (addr.indexOf("stop")>-1) {
    f_align.stopFO();
  }
}

void alignStart() {
  /* force testing 
   goFacet=100;
   f_align.setupFO();
   */
  if (bloom[2].equals(ipSelected) == true) {
    //  if (ipSelected==int(bloom[2])) {
    goFacet=100;
    f_align.setupFO();
  }
}
void cherishQuery() {
  for (int i=0;i<15;i++) {
    if (int(cherish[0])==i) {
      echoAction(7, i, 0.0);
    }
  }
}
void cherishSelect(OscMessage theOscMessage, String addr) {
  String buffer[] = split(addr, "/");
  int thisCherish = (int(buffer[4])-1);
  echoAction(6, thisCherish, 0.0);
}
